package com.demo2do.fms.entity.report;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.lang3.time.DateFormatUtils;

import com.demo2do.fms.entity.authority.Organization;

/**
 * 驾驶员报销信息 - 预约记录
 *
 * @author Ark
 *
 */
@Entity
@Table(name = "FMS_DRIVER_COST_APPOINTMENT")
public class DriverCostAppointment {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 预约号 */
    private String code;
    
    /** 开始处理时间 */
    private Date handleTime;
    
    /** 处理完成时间 */
    private Date finishTime;
    
    /** 报表状态 */
    @Enumerated(EnumType.STRING)
    private AppointmentStatus status;
    
    /** 报表文件url */
    private String url;
    
    /** 驳回理由 */
    private String reason;
    
    /** 预约条件 - 预约公司 */
    private Long organizationId;
    
    /** 预约条件 - 报销开始日期 */
    private String beginReimburseDate;
    
    /** 预约条件 - 报销结束日期 */
    private String endReimburseDate;
    
    /** 创建人 */
    private Long creator;

    /** 创建时间 */
    private Date createTime;

    /** 最后修改人 */
    private Long lastOperator;
    
    /** 最后修改时间 */
    private Date lastModifyTime;

    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /**
     * The default constructor
     */
    public DriverCostAppointment() {
    }

    /**
     * @param organization
     * @param operator
     * @return
     */
    public DriverCostAppointment initialize(Organization organization, Long operator) {
        this.code = "DC" + organization.getCode() + DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        this.status = AppointmentStatus.AUDITING;
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        this.disabled = false;
        return this;
    }
    
    /**
     * start handle appointment
     * 
     * @param operator
     * @return
     */
    public DriverCostAppointment start(Long operator) {
        this.handleTime = new Date();
        this.status = AppointmentStatus.PROCESSING;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * handle appointment success
     * 
     * @param url
     * @param operator
     * @return
     */
    public DriverCostAppointment success(String url, Long operator) {
        this.url = url;
        this.finishTime = new Date();
        this.status = AppointmentStatus.COMPLETED;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * handle appointment failed
     * 
     * @param operator
     * @return
     */
    public DriverCostAppointment fail(Long operator) {
        this.status = AppointmentStatus.FAILED;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public DriverCostAppointment delete(Long operator) {
        this.disabled = true;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the handleTime
     */
    public Date getHandleTime() {
        return handleTime;
    }

    /**
     * @return the finishTime
     */
    public Date getFinishTime() {
        return finishTime;
    }

    /**
     * @return the status
     */
    public AppointmentStatus getStatus() {
        return status;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }
    
    /**
     * @return
     */
    public String getReason() {
        return reason;
    }

    /**
     * @return
     */
    public Long getOrganizationId() {
        return organizationId;
    }

    /**
     * @return the beginReimburseDate
     */
    public String getBeginReimburseDate() {
        return beginReimburseDate;
    }

    /**
     * @return the endReimburseDate
     */
    public String getEndReimburseDate() {
        return endReimburseDate;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param handleTime the handleTime to set
     */
    public void setHandleTime(Date handleTime) {
        this.handleTime = handleTime;
    }

    /**
     * @param finishTime the finishTime to set
     */
    public void setFinishTime(Date finishTime) {
        this.finishTime = finishTime;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(AppointmentStatus status) {
        this.status = status;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }
    
    /**
     * @param reason
     */
    public void setReason(String reason) {
        this.reason = reason;
    }

    /**
     * @param organizationId
     */
    public void setOrganizationId(Long organizationId) {
        this.organizationId = organizationId;
    }

    /**
     * @param beginReimburseDate the beginReimburseDate to set
     */
    public void setBeginReimburseDate(String beginReimburseDate) {
        this.beginReimburseDate = beginReimburseDate;
    }

    /**
     * @param endReimburseDate the endReimburseDate to set
     */
    public void setEndReimburseDate(String endReimburseDate) {
        this.endReimburseDate = endReimburseDate;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }
    
}
